<template>
  <div class="m-nav">
    <ul class="nav">
      <li>
        <nuxt-link :to="'/order?id='+userId" >我的订单</nuxt-link>
      </li>
      <li>
        <nuxt-link to="/weChat">微信小程序</nuxt-link>
      </li>
      <li class="list bd">
        <nuxt-link to="/">商家中心</nuxt-link>
        <dl>
          <dd>
            <a href="http://127.0.0.1:8080">登录商家中心</a>
          </dd>
          <dd>
            <nuxt-link to="/shopRegister">我要入驻</nuxt-link>
          </dd>
        </dl>
      </li>
      <li v-if="cart != null" class="list site">
        <nuxt-link to="/cart" style="color: red;">
          <i class="el-icon-shopping-cart-full"></i>
          购物车&nbsp;{{this.cart.length}}
        </nuxt-link>
        <dl>
          <dd v-for="(item,i) in this.cart" v-bind:key="i">
            <nuxt-link to="/cart">{{item.name}}</nuxt-link>
          </dd>
        </dl>
      </li>
      <li v-else class="list site">
        <nuxt-link to="/cart" style="color: dodgerblue;">
          <i class="el-icon-shopping-cart-2"></i>购物车&nbsp;0
        </nuxt-link>
      </li>
    </ul>
  </div>
</template>
<script>
import * as homeApi from "@/server/home.js";
export default {
  data() {
    return {
      cart: null,
      userId: 0
    };
  },
  mounted() {
    this.getCart();
  },
  methods: {
    getCart: function() {
      var user = localStorage.getItem("user");
      if (user == null) {
        user = 0;
      }
      this.userId = user;
      homeApi.getCart(user).then(result => {
          this.cart = result.data.data;
      });
    }
  }
};
</script>

<style lang="css">
</style>
